package PTA.javaA;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Scanner;

public class ex21 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<PersonSortable2> array = new ArrayList<>();
        for(int i=0;i<n;i++){
            String str[]=sc.nextLine().split(" ");

            array.add(new PersonSortable2(str[0],Integer.valueOf(str[1])));
        }
        Collections.sort(array);
        for(PersonSortable2 i:array){
            System.out.println();
        }
    }
}
class PersonSortable2 implements  Comparable{
private String name;
private int age;
    public PersonSortable2(String name,int age){
        this.age= age;
        this.name=name;
    }
    public PersonSortable2(){
        this.name = name;
        this.age=age;
    }
    @Override
    public String toString(){
        return name+"-"+age;

    }

    @Override
    public int compareTo(Object o) {
        PersonSortable2 p = (PersonSortable2)o;
int x= this.name.compareTo(p.name);
if(x!=0){
    return 0;
}else{
    if(this.age<p.age){
        return -1;
    }else if(this.age>p.age){
return 1;
    }
        return 0;
    }
}
}